/*
 * This file is part of Smartfood.
 * 
 * Smartfood is Copyright (C) 2012 Thibault JACQUEMIN, Vincent KURIHARA
 * 
 * Smartfood is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * Smartfood is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * Smartfood. If not, see <http://www.gnu.org/licenses/>.
 */
package com.adapt;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;

import com.data.Instruction;
import com.data.ProductBase;
import com.smartfood.R;

/**
 * Adapter for the recipes listview
 */
public class InstructionAdapter extends ArrayAdapter<Instruction> {
	private Context context=null;
	private int layoutResourceId;
	private LayoutInflater mInflater;
	public InstructionAdapter(Context context,int layoutResourceId) {
		super(context,layoutResourceId);
		this.context=context;
		this.layoutResourceId=layoutResourceId;
	}
	public InstructionAdapter(Context context,int layoutResourceId,Instruction[] objects) {
		super(context,layoutResourceId,objects);
		this.context=context;
	}
	@Override
	public View getView(int position,View convertView,ViewGroup parent) {
         //if (convertView == null) {
             LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             convertView = vi.inflate(R.layout.list_custom, null);
             CheckedTextView nameText = (CheckedTextView) convertView.findViewById(R.id.text1);
             nameText.setText(getItem(position).toLongString());
         //}
		return convertView;
	}
	@Override
	public int getPosition(Instruction item) {
		int count=getCount();
		for(int i=0;i<count;i++) {
			if(item.getOrder()==getItem(i).getOrder())
				return i;
		}
		return -1;
	}
}